package com.yan.demo.method;

public class MethodDemo4 {
    public static void main(String[] args) {
        binaryConversion(10);
        System.out.println();
        System.out.println("----------------------");
        judgePrime(17);
    }

    // 求二进制
    public static void binaryConversion(int num) {
        int[] bit = new int[20];
        int index = -1;
        for (int i = 0; num > 0; i++) {
            bit[i] = num % 2;
            num = num / 2;
            index = i;
        }
        for (int i = index; i >= 0; i--) {
            System.out.print(bit[i]);
        }
    }

    // 判断是否为素数
    public static void judgePrime(int num) {
        boolean flag = true;
        for (int i = 2; i < num - 1; i++) {
            if(num % i == 0){
                flag = false;
                break;
            }
        }
        if(flag == true){
            System.out.println(num + "是素数");
        } else {
            System.out.println(num + "不是素数");
        }
    }
}
